// 提取问号传参的值(以及锚点)
function queryUrlParams(){
    //www.baidu.com?name=xxx&y==xx&#target，封装在对象中并返回
    let url = this;
    let res = {}
    url.replace(/([^?=+&]+)=([^?=+&]+)/g,(_,...arg)=>{
        res[arg[0]] = arg[1];
    })
    url.replace(/#([^?=+&]+)/g,(_,...arg)=>{
        res['#'] = arg[0];
    })
    return res;
}
String.prototype.queryUrlParams = queryUrlParams

// 本地缓存 部门列表
async function queryDepartment(){
    let departmentList = localStorage.getItem('departmentList');
    if(departmentList){
        // 如果有，先看看缓存是否过期
        if(new Date().getTime()-departmentList.time < 86400000 ){
            return departmentList.data;
        }
    }
    // 初次请求 或 缓存过期
    let result = await axios.get('/department/list');
    localStorage.setItem('departmentList',{
        time:new Date().getTime(),
        data:result
    })
    return result
}

// 本地缓存 职务列表
async function queryJob(){
    let jobList = localStorage.getItem('jobList');
    if(jobList){
        // 如果有，先看看缓存是否过期
        if(new Date().getTime()-jobList.time < 86400000 ){
            return jobList.data;
        }
    }
    // 初次请求 或 缓存过期
    let result = await axios.get('/job/list');
    localStorage.setItem('jobList',{
        time:new Date().getTime(),
        data:result
    })
    return result
}